Skip to content

feat(auth): admin password reset with session revocation - #25

Merged
dalpan merged 1 commit into
mainfrom
feature/admin-password-reset
Nov 9, 2026
Merged

dalpan merged 1 commit into
mainfrom
feature/admin-password-reset

Conversation

@dalpan

@dalpan dalpan commented Nov 9, 2026

Copy link
Copy Markdown
Owner

Summary

Administrators had no way to set another user's password. The only option was editing the database inside the container.

Admin reset: POST /api/auth/users/{id}/reset-password

  • Admin only. Self returns 400 (use change-password), another admin returns 403, an unknown user returns 404, and unknown fields return 422.
  • Same password policy as everywhere else.
  • require_change (default true) sets must_change_password on the account.
  • Audit entry auth.password.reset records the username and require_change, never the password.

Session revocation

  • User.token_version is added, and every JWT carries it as tv. get_current_user rejects a token whose version is older than the stored one, returning 401 "Session revoked".
  • A reset increments the version, so stolen or stale sessions end immediately. Before this, a JWT stayed valid for its full 24 hours.
  • Backward compatible: existing tokens without tv and users without the field both count as version 0, so nobody is signed out by the deploy.

Own password change

  • Rejects reusing the current password.
  • Clears must_change_password and signs out the user's other sessions.
  • Returns a fresh token, which ProfilePage stores so the current tab stays signed in.

UI

  • Users page: a "Reset Password" action on non-admin rows, opening a modal with a generator for a policy-compliant password and a "require change" toggle.
  • A "Must change password" badge on rows that still need a change.
  • A banner on every page that links to Profile until the user sets their own password.
  • Strings in EN and ID.

Tests

  • backend/tests/test_password_reset.py (6 tests) covers:
    • reset and revocation of old sessions
    • the forced-change flag
    • role checks (user, trainer, self, other admin, unknown user, weak password, extra fields)
    • change-password issuing a fresh token and revoking every other token
    • legacy tokens without tv still accepted
  • Full suite: 277 passed. ruff check and ruff format --check are clean. CI=true npm run build passes.

Notes

  • The forced change is a strong prompt (banner), not a hard block on other endpoints. Making it blocking is a small follow-up if wanted.

🤖 Generated with Claude Code

- POST /api/auth/users/{id}/reset-password (admin): sets a new password for
  another non-admin account, optionally requires a change at next login,
  and records an audit entry without the password. Self and other admins
  are refused.
- Session revocation: users carry token_version and JWTs carry it as "tv".
  A token with an older version is rejected, so a reset signs out every
  existing session. Tokens issued before this change carry no "tv", count
  as version 0 and keep working.
- change-password now rejects reusing the current password, clears
  must_change_password, signs out the user's other sessions and returns a
  fresh token that the profile page stores.
- UI: Reset Password action and modal on the Users page (password
  generator, require-change toggle), a "must change password" badge, and
  a banner linking to Profile until the user picks their own password.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dalpan
dalpan merged commit 2367f9f into main Nov 9, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant